package com.fly.push.job;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fly.push.service.DataService;
import com.fly.push.sse.SSEServer;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Component
public class PushJob
{
    ObjectMapper objectMapper = new ObjectMapper();
    
    @Autowired
    DataService dataService;
    
    @Scheduled(cron = "0/10 * * * * ?")
    public void run()
    {
        try
        {
            log.info("###### pushData again");
            SSEServer.batchSendMessage(objectMapper.writeValueAsString(dataService.getUsers()));
        }
        catch (Exception e)
        {
            log.error(e.getMessage(), e);
        }
    }
    
}
